# coding=utf-8
# -*- coding: UTF-8 -*-
#
# This file is part of the kernelstudio package.
#
# (c) 2014-2025 zlin <admin@kernelstudio.com>
#
# For the full copyright and license information, please view the LICENSE file
# that was distributed with this source code.

from pydantic import Field
from pydantic_settings import BaseSettings, SettingsConfigDict

from ksai.document.config import DocumentConfig

STATIC_FOLDER_NAME = "static"
STATIC_URL_PREFIX = "/"
STORAGE_FOLDER_NAME = "storage"
VIEWS_FOLDER_NAME = "views"
MODELS_FOLDER_NAME = "models"
LOGS_FOLDER_NAME = "logs"


def load_config() -> SettingsConfigDict:
    return SettingsConfigDict(
        # read from dotenv format config file
        env_file=".env",
        env_file_encoding="utf-8",
        # ignore extra attributes
        extra="ignore",
    )


class RuntimeConfig(BaseSettings):
    DEBUG: bool = Field(
        default=False,
        envvar='DEBUG'
    )

    APP_PORT: int = Field(
        default=4444,
        envvar='APP_PORT'
    )

    APP_HOST: str = Field(
        default='0.0.0.0',
        envvar='APP_HOST'
    )

    APP_EXTERNAL_URI: str = Field(
        default='http://127.0.0.1:4444',
        envvar='APP_EXTERNAL_URI'
    )

    APP_JSON_EXCEPTION: bool = Field(
        default=True,
        envvar='APP_JSON_EXCEPTION'
    )

    LOGGING_LEVEL: str = Field(
        default="INFO",
        envvar='LOGGING_LEVEL'
    )

    LOGGING_FILE_MAX_BYTES: int = Field(
        default=1024000,
        envvar='LOGGING_FILE_MAX_BYTES'
    )

    LOGGING_BACKUP_COUNT: int = Field(
        default=4,
        envvar='LOGGING_BACKUP_COUNT'
    )

    MAX_CONTENT_LENGTH: int = Field(
        default=50 * 1024 * 1024,
        envvar='MAX_CONTENT_LENGTH'
    )


class ApplicationConfig(
    RuntimeConfig,
    DocumentConfig,
):
    pass


app_config = ApplicationConfig()
